var id = getUrlParam("id");
localStorage.goUrl = "";
if(id=="" || id==null){
  noFound();
}else{
  $.ajax({
    url:"/coup/get/"+id,
    dataType:"json",
    success:function(res){
      if(res.result!=null){
        var img = res.result.img.length>0?res.result.img[0].imgUrl:'img/abg.png';
        document.getElementById("abg").setAttribute("src",img);
        document.getElementById("name").innerHTML = res.result.cName;
        document.getElementById("rule").innerHTML = res.result.rule;
      }else{
        noFound();
      }
    }
  });
}

document.getElementById("capture-btn").onclick=function(){
  // var phone = document.getElementById("phone-input").value;
  // var phoneRegx = /^1\d{10}$/;
  // if(!phoneRegx.test(phone)){
  //   alert("请输入正确的手机号");
  //   return;
  // }
  $.ajax({
    url:"/coup/add?cpid="+id,
    dataType:"json",
    success:function(res){
        console.log(res);
      if(res.code==200){
        alert("领取成功!");
      }
    },
    error:function(res){
      console.log(res);
      if(typeof(res.responseJSON)=="undefined"){
          alert("请先登录");
          localStorage.goUrl = location.href;
          location.href = "/login";
          // console.log(  location.href1)
      }else{
          alert(res.responseJSON.msg);
      }
    }
  });

}

function noFound(){
  document.getElementById("page_one").style.display= "none";
  document.getElementById("page_two").style.display= "block";
}
